package Java攻略._5_流式操作_lambda表达式与方法_引用的相关问题._4_Map接口的默认方法;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class _9_利用缓存计算斐波那契数 {

    private static Map<Long, BigInteger> map = new HashMap<>();

    public static BigInteger fib(long i){
        if(i == 0) return BigInteger.ZERO;
        if(i == 1) return BigInteger.ONE;
        return map.computeIfAbsent(
                i,
                n -> fib(n - 2).add(fib(n - 1))
                );
    }

    public static void main(String[] args) {
        System.out.println(fib(6));
    }


}
